<template>
  <div>
    <el-row>
        <b>雌雄：</b>
        <el-radio-group v-model="radio1" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">雄</el-radio-button>
        <el-radio-button label="2">雌</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>登记：</b>
        <el-radio-group v-model="radio2" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">已登记</el-radio-button>
        <el-radio-button label="2">未登记</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>注销：</b>
        <el-radio-group v-model="radio3" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">是</el-radio-button>
        <el-radio-button label="2">否</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>品种：</b>
        <el-input palceholder="请输入品种搜索" v-model="variety" style="width
        :250px;"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="initTable">查询</el-button>
    </el-row>
    <el-row>
        <b>毛色：</b>
        <el-input palceholder="请输入毛色搜索" v-model="color" style="width
        :250px;"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="initTable">查询</el-button>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="宠物名">
      </el-table-column>
      <el-table-column
        prop="petType"
        label="宠物类型">
      </el-table-column>
      <el-table-column
        prop="gender"
        label="雌雄">
        <template slot-scope="scope">
            <el-tag type="">{{ scope.row.gender == 1?"雄":"雌" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="variety"
        label="品种">
      </el-table-column>
      <el-table-column
        prop="color"
        label="毛色">
      </el-table-column>
      <el-table-column
        prop="isCheckIn"
        label="宠物登记">
        <template slot-scope="scope">
            <el-tag :type="scope.row.isCheckIn == 1?'success':'info'">{{ scope.row.isCheckIn == 1?"已登记":"未登记" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isLogOut"
        label="是否注销">
        <template slot-scope="scope">
          <el-tag :type="scope.row.isLogOut == 1?'success':'info'">{{ scope.row.isLogOut == 1?"已注销":"未注销" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="登记时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-search" @click="ToPetInfo(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
    </div>
</template>

<script>
export default {
    name:'pet',
    data(){
        return{
            radio1:'0',
            radio2:'0',
            radio3:'0',
            variety:'',
            color:'',
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
        }
    },
    created(){
      this.initAuthority()
    },
    methods:{
      initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 10
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
      ToPetInfo(id){
            this.$router.push({
            path: 'petInfo',
            query:{
                ID:id
            }
           })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            this.$request.get("/pet/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    gender:this.radio1,
                    isCheckIn:this.radio2,
                    isLogOut:this.radio3,
                    color:this.color,
                    variety:this.variety
                }
            }).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
            }).catch(err =>{
                console.log(err)
            })
        },
    }
}
</script>

<style>
    .el-row{
        margin-bottom: 20px;
    }
</style>